﻿using SqlSugar;
using System;
using System.Collections.Generic;
using System.Text;

namespace Infrastructure
{
    public class GeneralRepository<TEntity> : IGeneralRepository<TEntity> where TEntity : class
    {
        dynamic IGeneralRepository<TEntity>.Add(TEntity entity)
        { 
            using (var db = SugarDao.GetInstance())
            {
                db.IsEnableAttributeMapping = true;
                
                return db.Insert<TEntity>(entity,true);
            }
        }

        bool IGeneralRepository<TEntity>.Delete(TEntity entity)
        {
            using (var db = SugarDao.GetInstance())
            {
                return db.Delete(entity);

            }
        }

        bool IGeneralRepository<TEntity>.Update(TEntity entity)
        {
            using (var db = SugarDao.GetInstance())
            {
                return db.Update(entity);

            }
        }
    }
}
